<?php

/**
 * This is the model class for table "usuario".
 *
 * The followings are the available columns in table 'usuario':
 * @property integer $id_usu
 * @property string $usuario_usu
 * @property string $contrasena_usu
 * @property string $fecha_lim_act_usu
 * @property boolean $activo_usu
 *
 * The followings are the available model relations:
 * @property Proyecto $proyecto
 * @property Rol[] $rols
 * @property Estudiante[] $estudiantes
 */
class Usuario extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Usuario the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'usuario';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('usuario_usu, contrasena_usu, fecha_lim_act_usu, activo_usu', 'required'),
			array('usuario_usu', 'length', 'max'=>20),
			array('contrasena_usu', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_usu, usuario_usu, contrasena_usu, fecha_lim_act_usu, activo_usu', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'proyecto' => array(self::HAS_ONE, 'Proyecto', 'id_usu'),
			'rols' => array(self::MANY_MANY, 'Rol', 'usuario_rol(id_usu, id_rol)'),
			'estudiantes' => array(self::MANY_MANY, 'Estudiante', 'usuario_estudiante(id_usu, id_est)'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_usu' => 'Id Usu',
			'usuario_usu' => 'Usuario Usu',
			'contrasena_usu' => 'Contrasena Usu',
			'fecha_lim_act_usu' => 'Fecha Lim Act Usu',
			'activo_usu' => 'Activo Usu',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_usu',$this->id_usu);
		$criteria->compare('usuario_usu',$this->usuario_usu,true);
		$criteria->compare('contrasena_usu',$this->contrasena_usu,true);
		$criteria->compare('fecha_lim_act_usu',$this->fecha_lim_act_usu,true);
		$criteria->compare('activo_usu',$this->activo_usu);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}